package cn.wolfcode.java39.rocketmqconsumerdemo.api._01_hello;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

public class Producer {
    public static void main(String[] args) throws Exception{
        //创建一个生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("wolfcode-producer");
        //设置nameserver地址
        producer.setNamesrvAddr("192.168.136.128:9876;192.168.136.129:9876");
        //启动生产者
        producer.start();
        //创建一个message对象
        Message message = new Message("01-hello", "hello,rocketmq".getBytes("utf-8"));
        //使用同步的方式发送
        SendResult sendResult = producer.send(message);
        System.out.println(sendResult.getSendStatus());//打印发送状态
        System.out.println(sendResult.getMsgId());
        //关闭生产者
        producer.shutdown();
    }
}
